package ai4games_tests.tests;

import game2dai.World;
import game2dai.entities.Building;
import game2dai.entities.Vehicle;
import game2dai.entityshapes.ps.ArrowPic;
import game2dai.entityshapes.ps.BuildingPic;
import game2dai.entityshapes.ps.Hints;
import game2dai.maths.Vector2D;
import game2dai.steering.AutoPilot;
import processing.core.PApplet;

//Test adding buildings and wall avoidance

public class GameTest_012 extends PApplet{

	final boolean HINTS = false;

	World w;
	Building build0 = null;
	Building[] buildingArray = null;
	BuildingPic bpic = null;
	ArrowPic view;

	Vehicle v1, v2;
	Vehicle[] vs;
	
	AutoPilot sb1, sb2;

	Vector2D home1, home2;
	
	long ct, et, lt;
	float deltaTime;

	public void setup(){
		size(800,600);
		w = new World(width, height);

		home1 = new Vector2D(650, 450);
		home2 = new Vector2D(530, 550);


		buildingArray = Building.makeFromXML(this, "ai4g/gt012_building_1.xml");
		bpic = new BuildingPic(this);
		for(Building b : buildingArray){
			b.renderer(bpic);	
		}
		
		w.add(buildingArray[0]);
//		w.add(buildingArray[1]);
		

		sb1 = new AutoPilot();
//		sb1.enableBehaviours(SBF.ARRIVE | SBF.WALL_AVOID);
		sb1.arriveOn(home1).wallAvoidOn();
//		sb1.setTarget(SBF.ARRIVE, home1);

		vs = Vehicle.makeFromXML(this, "ai4g/gt012_vehicle_1.xml");
		v1 = vs[0];
		view = new ArrowPic(this);	
		view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY);
		v1.renderer(view);
		v1.AP(sb1);
		w.add(v1);
		
//		sb2 = new SB();
//		sb2.enableBehaviour(SBF.ARRIVE | SBF.WALL_AVOID);
		sb2 = (AutoPilot) sb1.clone();
//		sb2.setTarget(SBF.ARRIVE, home2);
		sb2.arriveOn(home2);

		System.out.println(sb1);
		System.out.println();

		System.out.println(sb2);
		v2 = vs[1];

		view = new ArrowPic(this);	
		view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY);
		v2.renderer(view);
		v2.AP(sb2);
		w.add(v2);
		
		ct = lt = millis();	
	}

	public void draw(){
		ct = millis();
		et = ct - lt;
		lt = ct;
		deltaTime = et / 1000.0f;

//		if(building.isOver(mouseX, mouseY))
		background(220,255,220);

		fill(0,64,0);
		noStroke();
		ellipseMode(CENTER);
		ellipse((float)home1.x, (float)home1.y, 14,14);
		ellipse((float)home2.x, (float)home2.y, 14,14);

		w.update(deltaTime);
		w.draw(0);
	}

}
